<template>
  <div>
    <h1>新闻资讯</h1>
    <ul class="mui-table-view">
      <li class="mui-table-view-cell mui-media" v-for="item in newslist" :key="item.id">
          <!-- 传参id，若要使用变量item.id，要先给to绑定为变量，再将路由地址字符串拼接上变量item.id -->
          <!-- :to="'/home/newsinfo/'+item.id" -->
        <router-link :to="'/home/newsinfo/'+item.id">
          <img class="mui-media-object mui-pull-left" :src="item.img_url" />
          <div class="mui-media-body">
             <h1>{{item.title}}</h1> 
            <p class="mui-ellipsis">
                <span>发表时间：{{item.add_time | dateFormat}}</span>
                <span>点击：{{item.click}}次</span>
            </p>
          </div>
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data(){
    return {
      newslist:[] //接收存储列表数据
    }
  },
  created(){
    this.getNewlist();
  },
  methods:{
    getNewlist(){
      this.$axios
      .get("api/getnewslist")
      .then(Response=>{
        this.newslist = Response.data.message;
      })
      .catch(error=>{
        console.log("新闻列表获取失败"+error);
      })
    }
  }
};
</script>

<style lang="scss" scoped>
.mui-media-body h1{
    font-size: 14px;
}
.mui-ellipsis{
    font-size: 12px;
    color: #a9b2c5;
    display: flex;
    justify-content: space-between;
}
</style>
